package hxy.scan.server.controller;

import hxy.scan.server.dao.mapper.StudentMapper;
import hxy.scan.server.dao.model.StudentModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class StudentController {


    @Resource
    StudentMapper studentMapper;


    @GetMapping("/student-create")
    public int create(StudentModel studentModel) {

        String name = studentModel.getName();

        if (name == null) {
            return 0;
        }
        String age = studentModel.getAge();

        return studentMapper.insert(studentModel);
    }


    @GetMapping("/student-list")
    public List<StudentModel> list() {
        List<StudentModel> studentModels = studentMapper.selectList(null);

        for (StudentModel studentModel : studentModels) {
            String name = studentModel.getName();
            if (name.equals("张三")) {
                log.info("有问题");
            }
            log.info(name);
        }


        return studentModels;
    }

    @DeleteMapping("/student-delete")
    public int delete(int name) {
        return studentMapper.deleteById(name);
    }


    @GetMapping("/student-update")
    public int update(StudentModel studentModel) {

        return studentMapper.updateById(studentModel);
    }
}
